package cn.com.homeyoda.aimate.aihealth.data.service;

import static cn.com.homeyoda.aimate.aihealth.utils.AppConstants.DEVICE_ID;
import static cn.com.homeyoda.aimate.aihealth.utils.AppConstants.FACE_ID;
import static cn.com.homeyoda.aimate.aihealth.utils.AppConstants.FAMILY_ID;
import static cn.com.homeyoda.aimate.aihealth.utils.AppConstants.PHONE;
import static cn.com.homeyoda.aimate.aihealth.utils.AppConstants.USER_ID;

import com.wzq.mvvmsmart.utils.SPUtils;

/**
 * Created By 刘纯贵
 * Created Time 2020/4/29
 */
public class LocalDataSourceImpl implements LocalDataSource {

    private volatile static LocalDataSourceImpl INSTANCE = null;

    public static LocalDataSourceImpl getInstance() {
        if (INSTANCE == null) {
            synchronized (LocalDataSourceImpl.class) {
                if (INSTANCE == null) {
                    INSTANCE = new LocalDataSourceImpl();
                }
            }
        }
        return INSTANCE;
    }

    public static void destroyInstance() {
        INSTANCE = null;
    }

    private LocalDataSourceImpl() {
        // 数据库Helper构建
    }

    @Override
    public void saveUserName(String userName) {
        SPUtils.getInstance().put("UserName", userName);
    }

    @Override
    public void savePassword(String password) {
        SPUtils.getInstance().put("password", password);
    }

    @Override
    public String getUserName() {
        return SPUtils.getInstance().getString("UserName");
    }

    @Override
    public String getPassword() {
        return SPUtils.getInstance().getString("password");
    }

    @Override
    public String getFamilyId() {
        return SPUtils.getInstance().getString(FAMILY_ID);
    }

    @Override
    public void saveFamilyId(String familyId) {
        SPUtils.getInstance().put(FAMILY_ID, familyId);
    }

    @Override
    public String getFaceId() {
        return SPUtils.getInstance().getString(FACE_ID);
    }

    @Override
    public void saveFaceId(String faceId) {
        SPUtils.getInstance().put(FACE_ID, faceId);
    }

    @Override
    public String getPhone() {
        return SPUtils.getInstance().getString(PHONE);
    }

    @Override
    public void savePhone(String phone) {
        SPUtils.getInstance().put(PHONE, phone);
    }

    @Override
    public String getUserId() {
        return SPUtils.getInstance().getString(USER_ID);
    }

    @Override
    public void saveUserId(String userId) {
        SPUtils.getInstance().put(USER_ID, userId);
    }

    @Override
    public void saveDeviceId(String deviceId) {
        SPUtils.getInstance().put(DEVICE_ID, deviceId);
    }

    @Override
    public String getDeviceId() {
        return SPUtils.getInstance().getString(DEVICE_ID);
    }
}
